package com.gxa.zhonglong.service.impl;

import com.gxa.zhonglong.common.ExceptionCode;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.mapper.SubbranchMapper;
import com.gxa.zhonglong.pojo.Subbranch;
import com.gxa.zhonglong.service.SubbranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author : 宸濯
 * Date: 2021/10/27 11:00
 * Description:
 * Version: V1.0
 */
@Service
public class SubbranchServiceImpl implements SubbranchService {

    @Autowired
    private SubbranchMapper subbranchMapper;
    @Override
    public List<Map<String, Object>> selectAllById(Long id) throws BusinessException {
        final List<Map<String, Object>> maps = subbranchMapper.selectAllById(id);
        if (maps.size()==0){
            throw new BusinessException(ExceptionCode.NODATA);
        }
        return maps;
    }

    @Override
    public Map<String, Object> selectById(Long id) {
        return subbranchMapper.selectById(id);
    }

    @Override
    public List<Map<String, Object>> selectIdAndName(Long id) {
        return subbranchMapper.selectIdAndName(id);
    }

    @Override
    public List<Map<String, Object>> selectAll() {
        return subbranchMapper.selectAll();
    }

    @Override
    public void add(Subbranch subbranch) throws BusinessException {
        if (!subbranchMapper.add(subbranch)) {
            throw new BusinessException(ExceptionCode.ADD_DEFEATED);
        }
    }

    @Override
    public void update(Subbranch subbranch) throws BusinessException {
        if (!subbranchMapper.update(subbranch)) {
            throw new BusinessException(ExceptionCode.UPDATE_FALSE);
        }
    }

    @Override
    public void del(Long id) throws BusinessException {
        if (!subbranchMapper.del(id)) {
            throw new BusinessException(ExceptionCode.DELETE_FALSE);
        }
    }
}
